<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>My notes</title>
<link rel="shortcut icon" href="__TMPL__Public/images/icon.png" />
<link type="text/css" rel="stylesheet" href="__TMPL__Public/css/common.css" media="all" />
<link type="text/css" rel="stylesheet" href="__TMPL__Book/css/showOneBook.css" media="all" />
<link type="text/css" rel="stylesheet" href="__TMPL__Book/css/incBookInfo.css" media="all" />

<link type="text/css" rel="stylesheet" href="__TMPL__Public/jquery/css/le-frog/jquery-ui-1.8.16.custom.css" media="all"  />
<script type="text/javascript" src="__TMPL__Public/jquery/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="__TMPL__Public/jquery/js/jquery-ui-1.8.16.custom.min.js"></script>

<script type="text/javascript" src="__TMPL__Public/js/common.js"></script>
<script type="text/javascript">
	$(function(){
		$("#add_comment_button").bind('click', addComment);
		$(".add_friend_button").bind('click', addFriend);
		$(".buttons").button().css("font-size","14px");
	});
	
    function addComment(){
        var book_id = $(this).attr('book_id');
        var content = $("#comment_content").val();
        $.post(APP_PATH +"Comment/add", {
            book_id: book_id,
            content:content
        }, function(result){
            result = JSON.parse(result);
			if(result.status == 1) {
				//TODO:这里更新DOM
				var div = $("<div/>").addClass("each_comment");
				var p = $("<p/>");
				p.append("<span class='font_style1'>"+MY_NAME+" 说：</span>");
				var input = $("<input type='button' value='加为好友' user_id="+MY_ID+" />");
				input.addClass("add_friend_button buttons");
				input.appendTo(p);
				p.appendTo(div);
				div.append("<p>"+content+"</p>");
				div.appendTo("#_comment");
				$(".add_friend_button").bind('click', addFriend);
				$(".buttons").button().css("font-size","14px");
			}
        });
    }


	function addFriend() {
		var user_id = $(this).attr('user_id');
		$.get(APP_PATH + "Friend/add", {
			friend_id : user_id
		}, function(result) {
			result = JSON.parse(result);
			if(result.status == 1) {
				alert("添加好友成功");
				//TODO:
			}
		});
	}
</script>
</head>
<body id="book_item">
	<include file="Public:header"/>
	<div id="main_panel">
		<include file="Book:incBookInfo"/>
			
		<div id="_comment">
		<h2>评论</h2>
		<input class="buttons" type="button" value="发布" book_id="{$book.id}" id="add_comment_button"/>		
		<textarea id="comment_content" cols="70" rows="8"></textarea>
		
		<volist name="comments" id="comment">
			<div class="each_comment">
				<p><span class="font_style1">{$comment.user.name} 说：</span>
				<input type="button" value="加为好友"
				class="add_friend_button buttons" user_id="{$comment.user_id}"/></p>
				<p>{$comment.content}</p>
			</div>
		</volist>
		</div>
		
		<in name="book.group_id" value="$user.group_ids">
			<h2>笔记</h2>
			<volist name="notes" id="note">
			<div class="each_note">
				<a class="buttons" href="__APP__/Note/showOneNote?note_id={$note.id}&book_id={$book.id}">点击查看</a>
				
				<span>（作者 {$note.user.name}） </span>
				<span>{$note.title}</span>
				
			</div>
		    </volist>
		</in>
	</div>
<include file="Public:common"/>
</body>
</html>